#ifndef Scroller_First
#define Scroller_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Box.h"

class ScrollBar;
class Clipper;

enum ScrollDir {
	eScrollNone       = 0,
	eScrollRight      = BIT(0),
	eScrollDown       = BIT(1),
	eScrollLeft       = BIT(2),
	eScrollUp         = BIT(3),
	eScrollHideScrolls= BIT(4),
	eScrollDefault    = eScrollRight | eScrollDown
};

const int cScrollBarSize= 20;

//---- Scroller ---------------------------------------------------------------

class Scroller: public CompositeVObject {
public:
	MetaDef(Scroller);
	Scroller(VObject *v= 0, const Point &e= gPoint0, int id= cIdNone,
					ScrollDir= (ScrollDir)(eScrollDefault|eScrollHideScrolls));
	Scroller(VObject *v, Ink *bg, const Point &e= gPoint0, int id= cIdNone,
					ScrollDir= (ScrollDir)(eScrollDefault|eScrollHideScrolls));

	Clipper *GetClipper();
	VObject *GetInner();
	ScrollBar *GetScrollBar(int i);

	void Draw(Rectangle);
	void Control(int, int, void*);

	void SetBgInk(Ink *);
	Ink *GetBgInk();

	void SetExtent(Point e);
	void SetOrigin(Point at);

	Metric GetMinSize();
	void ViewSizeChanged();
	bool NeedControls();
	void BubbleUpdate(const Point &bs);
	Command *Input(Point lp, Token &t, Clipper *vf);

	OStream& PrintOn(OStream&);
	IStream& ReadFrom(IStream&);

protected:
	virtual VObject *MakeInner();
	virtual Clipper *MakeClipper();
	virtual ScrollBar *MakeScrollBar(int id);

protected:
	ScrollBar *sb[4];
	VObject *inner, *vop;
	Clipper *vf;
	Point ms;
	ScrollDir controls, visibleControls;
};

//---- MarginScroller ---------------------------------------------------------

class MarginScroller: public Scroller {
public:
	MetaDef(MarginScroller);
	MarginScroller(VObject *v, const Point &margin, const Point &e= gPoint0);
	virtual Point DoCalcMargin();

protected:
	VObject *MakeInner();
	void Control(int id, int part, void *v);

protected:
	Point margin;
	Clipper *cl[2];
};

#endif

